﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Ssb.Logic
{
    public sealed class Physics
    {
        /// <summary>
        /// Same as collides with Bubble, but tests for rectangles instead. Basically, makes strategic use of
        /// isPointInsideRectangle on each corner of each rectangle.
        /// </summary>
        /// <param name="rect">The rectangle to test</param>
        /// <returns></returns>
        public static bool doRectanglesCollide(Rectangle rect, Rectangle rectx)
        {            
                //Test both rectangles (collider & collidee) if they're inside eachother
            return isPointInsideRectanle(new Vector2(rect.X + rect.Width, rect.Y), rectx) &&  // topright
                isPointInsideRectanle(new Vector2(rect.X, rect.Y + rect.Height), rectx) && // bottomleft
                isPointInsideRectanle(new Vector2(rect.X + rect.Width, rect.Y + rect.Height), rectx) && // bottomright
                isPointInsideRectanle(new Vector2(rect.X, rect.Y), rectx) && // topleft
                isPointInsideRectanle(new Vector2(rectx.Location.X, rectx.Location.Y), rect) &&
                isPointInsideRectanle(new Vector2(rectx.Location.X + rectx.Width, rectx.Location.Y), rect) &&
                isPointInsideRectanle(new Vector2(rectx.Location.X, rectx.Location.Y + rectx.Height), rect) &&
                isPointInsideRectanle(new Vector2(rectx.Location.X + rectx.Width, rectx.Location.Y + rectx.Height), rect);        
        }

        /// <summary>
        /// Physics. Checks if the provided point is inside the provided rectangle.
        /// </summary>
        /// <param name="point">The point to check against the rectangle</param>
        /// <param name="BBox">The box to check against.</param>
        /// <returns>Whether or not the point is in the box.</returns>
        public static bool isPointInsideRectanle(Vector2 point, Rectangle BBox)
        {
            return (point.X > BBox.Left && point.X < BBox.Right) && (point.Y > BBox.Top && point.Y < BBox.Bottom);
        }
    }
}
